import { http } from "../../utils"
export default {
    namespaced:true,
    state:{
        hots:[],
        waits:[],
        detail:[],
        crews:[],
        comment:[],
        ct:"广州",
        id:440100
    },
    mutations:{
        setHots(state,hots){
            state.hots=hots
        },
        setWaits(state,waits){
          state.waits=waits
      },
        setDetail(state,detail){
            state.detail=detail
        },
        setCrews(state,crews){
            state.crews=crews
        },
        setComment(state,comment){
            state.comment=comment
        },
        setCity(state,ct){
            state.ct=ct
       },
       setCityId(state,id){
           state.id = id 
       },
    },
    actions:{
         //查询切换城市数据
         changeCity({commit},ct){
            commit('setCity',ct)
         },
         getCityId({commit},id){
            commit('setCityId',id)
         },

         

      //热映
       getAllHots({commit},n){
           http.get(`/api/mmdb/movie/v2/list/hot.json?limit=${n*12+12}&offset=0&ct=广州`).then(res=>{
              commit('setHots',res.data.data.hot)
           })
       },
       //待映
       getAllWaits({commit},n){
        http.get(`/api/mmdb/movie/v1/list/wish/order/coming.json?ci=20&limit=30&offset=0`).then(res=>{
           commit('setWaits',res.data.data.coming)
           console.log();
        })
    },
       //电影详情
       getDetail({commit},Id){
        http.get(`/api/mmdb/movie/v5/${Id}.json`).then(res=>{
           commit('setDetail',res.data.data.movie)
         })
       },
       //演员表
       getCrews({commit},id){
        http.get(`/api/mmdb/v7/movie/${id}/celebrities.json`).then(res=>{
              commit('setCrews',res.data.data)
          })
      },

    //  评论
      getComment({commit},id){
        http.get(`/api/mmdb/comments/movie/v2/${id}.json`).then(res=>{
              commit('setComment',res.data.cmts)
              console.log(res.data.cmts);
          })
      },
    }
}